#pragma once


namespace xBase
{

    class CxWaitableEvent
    {
    public:
        CxWaitableEvent(BOOL bManualReset, BOOL bInitiallySignaled);
        ~CxWaitableEvent(VOID);

        // Create a WaitableEvent from an Event HANDLE which has already been
        // created. This objects takes ownership of the HANDLE and will close it when
        // deleted.
        explicit CxWaitableEvent(HANDLE hEvent);

        // Releases ownership of the handle from this object.
        HANDLE Release();

        // Put the event in the un-signaled state.
        VOID Reset();

        // Put the event in the signaled state.  Causing any thread blocked on Wait
        // to be woken up.
        VOID Signal();

        // Returns true if the event is in the signaled state, else false.  If this
        // is not a manual reset event, then this test will cause a reset.
        BOOL IsSignaled();

        // Wait indefinitely for the event to be signaled.  Returns true if the event
        // was signaled, else false is returned to indicate that waiting failed.
        BOOL Wait(DWORD dwMilliSecond = INFINITE);

        HANDLE Handle() const { return m_hEvent; }

        static CxWaitableEvent* WaitMany(CxWaitableEvent ** ppEvents, UINT nCount);

    private:
        HANDLE m_hEvent;
    };

}